
	** Uganda 
	** Clean wave 2

	** Urban status
	
		use "$dir/rawdata/LSMS Uganda/2010/GSEC1.dta", clear
		gen w2_urban=urban==1
		
		keep HHID w2*
		ren HHID hhid
		
		tempfile urban
		save `urban', replace
		
	** Roster
		use "$dir/rawdata/LSMS Uganda/2010/GSEC2.dta", clear
		
		gen w2_female=h2q3==0 if !missing(h2q3)
		gen w2_age=h2q8
		gen w2_married=(h2q10==1 | h2q10==2) if !missing(h2q10)
		
		gen w2_inhh=h2q7<=4
		
		bys HHID: egen w2_hh_size=total(w2_inhh)
		
		ren HHID hhid
		ren PID indiv
		
		keep hhid indiv w2_*
		tempfile roster
		save `roster', replace
		
	** Illness or injury
	
		use "$dir/rawdata/LSMS Uganda/2010/GSEC5.dta", clear
	
		gen w2_illinj=h5q4==1 if !missing(h5q4)
		gen w2_illinjstopactivities=h5q6>0 if !missing(h5q6)
		replace w2_illinjstopactivities=0 if w2_illinj==0
		
		ren HHID hhid
		ren PID indiv 
		
		keep hhid indiv w2_*		
		tempfile illinj
		save `illinj', replace
		
	** Employment 
		
		use "$dir/rawdata/LSMS Uganda/2010/GSEC8.dta", clear
		
		gen w2_work_outsideHH=h8q4==1 if !missing(h8q4)
		
		gen w2_work_bizHH=(h8q6==1 | h8q8==1) if (!missing(h8q6) | !missing(h8q8))
		
		gen w2_work_agHH=(h8q12==1) if !missing(h8q12)
		
		egen w2_worked_last7days=rowmax(w2_work_outsideHH w2_work_agHH w2_work_bizHH)
		
		egen w2_work_hrs=rowtotal(h8q36a h8q36b h8q36c h8q36d h8q36e h8q36f h8q36g h8q43), mi // inludes working on a household business, agriculture, etc.
		
		ren HHID hhid
		ren PID indiv
		keep hhid indiv w2_*
		
		tempfile employment
		save `employment', replace

	** Disabilities

		use "$dir/rawdata/LSMS Uganda/2010/GSEC7A.dta", clear

		** Difficulty seeing
		tab1 h7q2a, nol
		tab1 h7q2a
		gen w2_diff_seei=1 if inlist(h7q2a, 2, 3, 4) 
		replace w2_diff_seei=0 if inlist(h7q2a, 1)
		replace w2_diff_seei=. if inlist(h7q2a, .)
		tab1 w2_diff_seei

		** Difficulty hearing
		tab1 h7q3a, nol
		tab1 h7q3a
		gen w2_diff_hear=1 if inlist(h7q3a, 2, 3, 4) 
		replace w2_diff_hear=0 if inlist(h7q3a, 1)
		replace w2_diff_hear=. if inlist(h7q3a, .)
		tab1 w2_diff_hear

		** Difficulty walking or climbing stairs	
		tab1 h7q4a, nol
		tab1 h7q4a
		gen w2_diff_walk_clim=1 if inlist(h7q4a, 2, 3, 4) 
		replace w2_diff_walk_clim=0 if inlist(h7q4a, 1)
		replace w2_diff_walk_clim=. if inlist(h7q4a, .)
		tab1 w2_diff_walk_clim

		** Difficulty remembering or concentrating
		tab1 h7q5a, nol
		tab1 h7q5a
		gen w2_diff_reme=1 if inlist(h7q5a, 2, 3, 4) 
		replace w2_diff_reme=0 if inlist(h7q5a,1)
		replace w2_diff_reme=. if inlist(h7q5a, .)
		tab1 w2_diff_reme

		** Difficulty with self-care
		tab1 h7q6a, nol
		tab1 h7q6a
		gen w2_diff_self_care=1 if inlist(h7q6a, 2, 3, 4)
		replace w2_diff_self_care=0 if inlist(h7q6a, 1)
		replace w2_diff_self_care=. if inlist(h7q6a, .)
		tab1 w2_diff_self_care

		** Difficulty communicating
		tab1 h7q7a, nol
		tab1 h7q7a
		gen w2_diff_comm=1 if inlist(h7q7a, 2, 3, 4) 
		replace w2_diff_comm=0 if inlist(h7q7a, 1)
		replace w2_diff_comm=. if inlist(h7q7a, .)
		tab1 w2_diff_comm

		rename HHID hhid
		rename PID indiv
		keep hhid indiv w2_*
		tempfile disabilities
		save `disabilities', replace
		
	** Merge and save
	
		use `roster', clear
		merge 1:1 hhid indiv using `illinj', gen(merge_illinj)
		merge 1:1 hhid indiv using `employment', gen(merge_employment)
		merge 1:1 hhid indiv using `disabilities', gen(merge_disabilities)
		merge m:1 hhid using `urban', gen(merge_urban)
		
		save "$dir/data/uga_w2_individual.dta", replace
